package com.jdrx.ocp.api;

import com.jdrx.logger.bizlogs.anno.BizLogger;
import com.jdrx.ocp.beans.commons.SysConstant;
import com.jdrx.ocp.beans.dto.company.AddCompanyDTO;
import com.jdrx.ocp.beans.dto.company.UpdateCompanyDTO;
import com.jdrx.ocp.service.CompanyService;
import com.jdrx.platform.common.support.gateway.GwConstants;
import com.jdrx.platform.commons.rest.beans.dto.IdDTO;
import com.jdrx.platform.commons.rest.beans.vo.ResposeVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 公司管理 Api
 * @author : zhongsen
 * @date : 2019/01/30 10:40
 */
@RestController
@Api(value="公司管理",description = "公司管理")
@RequestMapping(value = "/api/0/company/")
public class CompanyApi {
    @Autowired
    private CompanyService companyService;

    @RequestMapping(value = "addCompany",method = RequestMethod.POST)
    @ApiOperation(value = "添加公司",notes = "添加公司")
    //@BizLogger(description = "添加公司",serviceId = SysConstant.APPLICATION_NAME)
    public ResposeVO addCompany(@RequestBody @Valid AddCompanyDTO addCompanyDTO,
                                @RequestHeader(GwConstants.TRANSPARENT_USERID_FEILD)Long uid) throws BizException {
        return ResponseFactory.ok(companyService.addCompany(addCompanyDTO,uid));
    }

    @RequestMapping(value = "updateCompanyById",method = RequestMethod.POST)
    @ApiOperation(value = "根据id修改公司",notes = "根据id修改公司")
    //@BizLogger(description = "修改公司",serviceId = SysConstant.APPLICATION_NAME)
    public ResposeVO updateCompanyById(@RequestBody @Valid UpdateCompanyDTO updateCompanyDTO,
                                       @RequestHeader(GwConstants.TRANSPARENT_USERID_FEILD)Long uid) throws BizException {
        return ResponseFactory.ok(companyService.updateCompanyById(updateCompanyDTO,uid));
    }

    @RequestMapping(value = "deleteCompanyById",method = RequestMethod.POST)
    @ApiOperation(value = "根据id删除公司",notes = "根据id删除公司")
    //@BizLogger(description = "删除公司",serviceId = SysConstant.APPLICATION_NAME)
    public ResposeVO deleteCompanyById(@RequestBody @Valid IdDTO<Integer> idDTO) throws BizException {
        return ResponseFactory.ok(companyService.deleteCompanyById(idDTO));
    }

    @RequestMapping(value = "getCompanyById",method = RequestMethod.POST)
    @ApiOperation(value = "根据id获取公司",notes = "根据id获取公司")
    public ResposeVO getCompanyById(@RequestBody @Valid IdDTO<Integer> idDTO){
        return ResponseFactory.ok(companyService.getCompanyById(idDTO));
    }
}
